<?php
   	include_once('class/autoload.php');   // pour inclure nos classes
   	session_start();
	$site = new page_base('login');
	
	$site->titre = " login ";
	if(isset($_SESSION['login']))
	{
		echo 'Vous etes deja connecte';
	}
	else {
		
	$site->corps = "
	<head>
	<meta http-equiv='Content-type' content='text/html; charset=utf-8'>
	<title>jQuery Form Validation</title>
	<link rel='stylesheet' href='styles/css/validationEngine.jquery.css' type='text/css' media='screen' title='no title' charset='utf-8'>
	<link rel='stylesheet' href='styles/css/template.css' type='text/css' media='screen' title='no title' charset='utf-8'>
	<script src='styles/js/jquery.js' type='text/javascript'></script>
	<script src='styles/js/jquery.validationEngine-fr.js' type='text/javascript'></script>
	<script src='styles/js/jquery.validationEngine.js' type='text/javascript'></script>
	
	</head>
	<body>
	<form id='formID' class='formular' method='post' action=''>
	
	<legend>Connexion</legend>
	<fieldset>
	<label>
	<span>Login : </span>
	<input class='validate[optional,custom[noSpecialCaracters],length[0,40]]' name='login' id='login' type='text'>
	</label>
	<label>
	<span>Mot de passe : </span>
	<input class='validate[optional,custom[noSpecialCaracters],length[0,40]' name='password' id='password' type='password'>
	</label>
	<p><input class='submit' value='Valider' type='submit'></p>
	</fieldset>
	</form>
	</body>
	";}



    if(isset($_POST['login'], $_POST['password'])){
        require 'connect.php';

        $query = dbConnect()->prepare("SELECT loginUser, passwordUser FROM user WHERE loginUser=:login AND passwordUser=:password");
        $query->bindParam(':login', $_POST['login']);
        $query->bindParam(':password', $_POST['password']);
        $query->execute();

        if($row = $query->fetch()){
            $_SESSION['login'] = $row['loginUser'];
            header("Location: Accueil.php");
            
        }
        else {
        	echo 'Erreur de saisie';
        }
    }
    
    $site->affiche();
?>
